home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / unix / textmstr.shr / tm.hqx / Source Code ƒ / P / PD_Help_window.c < prev    next >
Text File  |  1991-05-09  |  9KB  |  246 lines

  1. /* PD_Help_window */
  2.  
  3. /* File name: Help_window */
  4. /* Function: Handle a modal dialog */
  5. /* History: 5/9/91 Original by Prototyper 3.0   */
  6.  
  7.  
  8. #include "PCommonTextMaster.h"    /* Common */
  9. #include "Common_TextMaster.h"    /* Common */
  10. #include "PUtils_TextMaster.h"    /* General Utilities */
  11. #include "Utils_TextMaster.h"    /* General Utilities */
  12.  
  13. #include "PD_Help_window.h"    /* This file */
  14. #include "Help_window.h"    /* The user file */
  15.  
  16.  
  17. /* ======================================================= */
  18.  
  19.  
  20. static Boolean        ExitDialog;                                             /* Flag used to exit the Dialog */
  21. static Point    MyPt;                                                         /* Current list selection point */
  22. static OSErr    MyErr;                                                      /* OS error returned */
  23. static DialogPtr    GetSelection;                                           /* Pointer to this dialog */
  24. static GrafPtr        SavedPort;                                            /* Previous grafport */
  25.  
  26. /* Prototypes */
  27. /* Filter routine for modal dialog routine */
  28. static pascal Boolean MyFilter (DialogPtr theDialog ,EventRecord *theEvent,short *itemHit);
  29.  
  30. /* This is an update routine for non-controls in the dialog */
  31. /* This is executed after the dialog is uncovered by an alert */
  32. static void Refresh_Dialog(void);                                         /* Refresh the dialogs non-controls */
  33.  
  34.  
  35.  
  36. /* ======================================================= */
  37.  
  38. /* Initialize the modal dialog, globals and call users routine */
  39.  
  40. void I_PD_Help_window()
  41. {
  42. Rect    tempRect;                                                            /* Temporary rectangle */
  43. short    DType;                                                               /* Type of dialog item */
  44. short    Index;                                                                /* For looping */
  45. Handle    DItem;                                                              /* Handle to the dialog item */
  46. ControlHandle    CItem, CTempItem;                                      /* Control handle */
  47. Str255    sTemp;                                                            /* Get text entered, temp holding */
  48. short    itemHit;                                                             /* Get selection */
  49. short    temp;                                                                 /* Get selection, temp holding */
  50.  
  51.  
  52.  
  53.  
  54. D_Init_Help_window();
  55.  
  56. }                                                                                /* End of procedure */
  57.  
  58.  
  59. /* ======================================================= */
  60.  
  61. /* Filter routine for dialog events */
  62.  
  63. static pascal Boolean MyFilter (theDialog ,theEvent,itemHit)
  64. DialogPtr    theDialog;
  65. EventRecord        *theEvent;
  66. short        *itemHit;
  67. {
  68. Point    MyPt;                                                                /* Current list selection point */
  69. Rect    tempRect;                                                            /* Temporary rectangle */
  70. short    DType;                                                               /* Type of dialog item */
  71. Handle    DItem;                                                              /* Handle to the dialog item */
  72. ControlHandle    CItem;                                                     /* Control handle */
  73. short    chCode;                                                              /* Key entered */
  74. long    LTemp;                                                                /* Used for time delay */
  75. char    MyCmdKey;                                                          /* The command key */
  76. Boolean    CmdDown;                                                        /* Flag for command key used */
  77. Boolean    valMyFilter;                                                     /* Value to return */
  78.  
  79.  
  80.  
  81. valMyFilter = D_Filter_Help_window(theDialog, theEvent, itemHit);/* Call the user routine */
  82.  
  83. if ((theEvent->what == updateEvt)  && ((WindowPtr)theEvent->message == theDialog))/* Only do on an update */
  84.     {
  85.     BeginUpdate(theDialog);                                                 /* Start the update */
  86.     DrawDialog(theDialog);                                                  /* Draw the controls */
  87.     valMyFilter = TRUE;                                                     /* Pass out this special itemHit number */
  88.     *itemHit = 32000;                                                       /* Our special ID */
  89.     }
  90. if (theEvent->what == mouseDown)                                      /* Only do on a mouse click */
  91.     {
  92.     MyPt = theEvent->where;                                              /* Get the point where the mouse was clicked */
  93.     GlobalToLocal(&MyPt);                                                 /* Convert global to local */
  94.  
  95.  
  96.     }
  97. if (theEvent->what == keyDown)
  98.     {
  99.     chCode =  theEvent->message & charCodeMask;                     /* Get character */
  100.     MyCmdKey = (char)chCode;                                             /* Change to ASCII */
  101.     CmdDown = ((theEvent->modifiers / cmdKey) != 0);               /* Get command key state */
  102.     if (CmdDown == TRUE)                                                  /* Do if command key was down */
  103.         {
  104.         if ((MyCmdKey == 'x') || (MyCmdKey == 'X'))
  105.             {
  106.             DlgCut(theDialog);
  107.             valMyFilter = TRUE;
  108.             }
  109.         else if ((MyCmdKey =='c') || (MyCmdKey == 'C')) 
  110.             {
  111.             DlgCopy(theDialog);
  112.             valMyFilter = TRUE;
  113.             }
  114.         else if ((MyCmdKey =='v') || (MyCmdKey == 'V'))
  115.             {
  116.             DlgPaste(theDialog);
  117.             valMyFilter = TRUE;
  118.             }
  119.         }
  120.     else if ((chCode == 13) || (chCode == 3))                             /* CR or Enter */
  121.         {
  122.         valMyFilter = TRUE;                                                  /* Flag we got a hit */
  123.         *itemHit = 1;                                                          /* Default for CR */
  124.         GetDItem (theDialog ,*itemHit, &DType, &DItem, &tempRect);/* Get the item */
  125.         if (DType == (ctrlItem + btnCtrl))                                 /* If a button then ... */
  126.             {
  127.             CItem = (ControlHandle)DItem;                                  /* Make it a controlhandle */
  128.             HiliteControl(CItem, 10);                                         /* Hilite it */
  129.             LTemp = TickCount() + 15;                                       /* Flash the button for 1/4 second */
  130.             do
  131.                 {}
  132.             while (LTemp > TickCount());
  133.             HiliteControl(CItem, 0);                                          /* UnHilite it */
  134.             }
  135.         }
  136.     }
  137.  
  138. return(valMyFilter);
  139. }
  140.  
  141. /* ======================================================= */
  142.  
  143.  
  144.  
  145. /* ======================================================= */
  146.  
  147. /* This is an update routine for non-controls in the dialog */
  148. /* This is executed after the dialog is uncovered by an alert */
  149. static void Refresh_Dialog()                                               /* Refresh the dialogs non-controls */
  150. Rect    rTempRect;                                                          /* Temp rectangle used for drawing */
  151. short    DType;                                                               /* Type of dialog item */
  152. Handle    DItem;                                                              /* Handle to the dialog item */
  153. ControlHandle    CItem;                                                     /* Control handle */
  154.  
  155.  
  156.  
  157. SetPort(GetSelection);                                                     /* Point to our dialog window */
  158. GetDItem(GetSelection,Res_Dlg_More,&DType,&DItem,&tempRect);/* Get the item handle */
  159. PenSize(3, 3);                                                               /* Change pen to draw thick default outline */
  160. InsetRect(&tempRect, -4, -4);                                            /* Draw outside the button by 1 pixel */
  161. FrameRoundRect(&tempRect, 16, 16);                                  /* Draw the outline */
  162. PenSize(1, 1);                                                               /* Restore the pen size to the default value */
  163.  
  164.  
  165. D_Refresh_Help_window(GetSelection);                                 /* Call user refresh routine */
  166.  
  167. }
  168.  
  169. /* ======================================================= */
  170.  
  171.  
  172. void PD_Help_window()
  173. {
  174. Rect    tempRect;                                                            /* Temporary rectangle */
  175. short    DType;                                                               /* Type of dialog item */
  176. short    Index;                                                                /* For looping */
  177. Handle    DItem;                                                              /* Handle to the dialog item */
  178. ControlHandle    CItem;                                                     /* Control handle */
  179. ControlHandle    CTempItem;                                               /* temp Control handle */
  180. Str255    sTemp;                                                            /* Get text entered, temp holding */
  181. short    itemHit;                                                             /* Get selection */
  182. short    temp;                                                                 /* Get selection, temp holding */
  183.  
  184.  
  185.  
  186. GetPort(&SavedPort);                                                     /* Get the previous grafport */
  187.  
  188.  
  189. GetSelection = GetNewDialog(Res_D_Help_window, NIL,  (Ptr)-1);/* Bring in the dialog resource */
  190. ShowWindow(GetSelection);                                               /* Open a dialog box */
  191. SelectWindow(GetSelection);                                              /* Lets see it */
  192. SetPort(GetSelection);                                                     /* Prepare to add conditional text */
  193.  
  194.  
  195. /* Setup initial conditions */
  196. Refresh_Dialog();                                                            /* Draw any Lists, lines, or rectangles */
  197.  
  198. ExitDialog = FALSE;                                                         /* Do not exit dialog handle loop yet */
  199.  
  200. D_Setup_Help_window(GetSelection);                                    /* Call user Dialog setup routine */
  201.  
  202. do                                                                              /* Start of dialog handle loop */
  203.     {
  204.     ModalDialog(&MyFilter, &itemHit);                                   /* Wait until an item is hit */
  205.  
  206.     if (itemHit == 32000)                                                   /* Check for update */
  207.         {
  208.         Refresh_Dialog();                                                      /* Draw any Lists, lines, or rectangles*/
  209.         EndUpdate(GetSelection);                                             /* End of the update*/
  210.         }
  211.     else
  212.         {
  213.         GetDItem(GetSelection, itemHit, &DType, &DItem, &tempRect);/* Get item information */
  214.         CItem = (ControlHandle)DItem;                                     /* Get the control handle */
  215.         }
  216.  
  217.     D_Hit_Help_window(GetSelection,itemHit,&ExitDialog);          /* Let user handle the item hit */
  218.  
  219.     /* Handle it real time */
  220.     if (itemHit ==Res_Dlg_More)                                           /* Handle the Button being pressed */
  221.         {
  222.         Add_UserEvent(UserEvent_Open_Window,Res_D_Help_window_2,0,0,NIL);/* Open a modal dialog */
  223.         ExitDialog = TRUE;                                                    /* Close this dialog, exit */
  224.         }
  225.  
  226.     if (itemHit ==Res_Dlg_OK2)                                            /* Handle the Button being pressed */
  227.         {
  228.         ExitDialog = TRUE;                                                    /* Close this dialog, exit */
  229.         }
  230.  
  231.  
  232.     }
  233. while (ExitDialog == FALSE);                                              /* Handle dialog items until exit selected */
  234.  
  235.  
  236. D_Exit_Help_window(GetSelection);                                     /* Exiting the modal dialog */
  237.  
  238. SetPort(SavedPort);                                                        /* Restore the previous grafport */
  239.  
  240. DisposDialog(GetSelection);                                                /* Flush the dialog out of memory */
  241.  
  242.  
  243. }                                                                                /* End of procedure */
  244.  
  245.